﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKSparseDistance.ModelLayer;
using YJKInspectModelFunc.ControlLayer;
using YJKInspectModelFunc.ModelLayer;

namespace YJKSparseDistance
{
	[Transaction(TransactionMode.Manual)]
	internal class TestCmd_CurveCutLink : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			UIApplication application = commandData.Application;
			Application application2 = application.Application;
			UIDocument activeUIDocument = application.ActiveUIDocument;
			Document document = activeUIDocument.Document;
			List<Level> list = new List<Level>();
			List<Phase> list2 = new List<Phase>();
			list.Add(activeUIDocument.ActiveView.GenLevel);
			foreach (object obj in document.Phases)
			{
				Phase item = (Phase)obj;
				list2.Add(item);
			}
			List<RoomPacker_EvacuationDistance> roomPacker = BaseRoomFinder<RoomPacker_EvacuationDistance, BaseDoorPacker, BountarySegmentPacker_EvacuationDistance, ObstructurePacker_EvacuationDistance>.GetRoomPacker(document, list, list2, new List<BuiltInCategory>
			{
				(BuiltInCategory)(-2000120),
				(BuiltInCategory)(-2000100),
				(BuiltInCategory)(-2000898),
				(BuiltInCategory)(-2000126)
			}, null, null, null, null);
			List<RoomCurveBean> list3 = new List<RoomCurveBean>();
			foreach (RoomPacker_EvacuationDistance inputValue in roomPacker)
			{
				list3.Add(new RoomCurveBean(inputValue));
			}
			for (int i = 0; i < list3.Count; i++)
			{
				for (int j = 0; j < list3.Count; j++)
				{
					if (i < j)
					{
						list3[i].SetLinkedRoom(list3[j]);
					}
				}
			}
			Transaction transaction = new Transaction(document, "test");
			transaction.Start();
			foreach (RoomCurveBean roomCurveBean in list3)
			{
				foreach (BulidingCurvePakcer bulidingCurvePakcer in roomCurveBean.LstCurvePacker)
				{
					if (null != bulidingCurvePakcer.ThisCurve && !bulidingCurvePakcer.IfCanGo)
					{
						document.Create.NewDetailCurve(activeUIDocument.ActiveView, bulidingCurvePakcer.ThisCurve);
					}
				}
				foreach (BulidingCurvePakcer bulidingCurvePakcer2 in roomCurveBean.LstObstructureCurvePacker)
				{
					if (null != bulidingCurvePakcer2.ThisCurve && !bulidingCurvePakcer2.IfCanGo)
					{
						document.Create.NewDetailCurve(activeUIDocument.ActiveView, bulidingCurvePakcer2.ThisCurve);
					}
				}
			}
			transaction.Commit();
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
